package com.example.demo.system.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.example.demo.annotation.ApiDesc;
import com.example.demo.entity.DictEntity;
import com.example.demo.entity.FileEntity;
import com.example.demo.entity.LoginEnity;
import com.example.demo.entity.LoginRole;
import com.example.demo.entity.MenuEntity;
import com.example.demo.entity.Organization;
import com.example.demo.entity.base.PageRequestBean;
import com.example.demo.entity.base.PageResponseBean;
import com.example.demo.entity.base.ResponseEntity;
import com.example.demo.entity.base.TreeEntity;
import com.example.demo.system.service.SystemManageService;
import com.example.demo.util.TokenUtil;

@RestController
@RequestMapping(value="/system/systemmanage")
public class SystemManageController {
	
	@Autowired
	private SystemManageService systemManageService;
	
	@ApiDesc("刷新超级管理员菜单权限")
	@RequestMapping(value="/refreshsuperauthor")
	public Object refreshSuperAuthor(HttpServletRequest request) {
		
		ResponseEntity<String> ret = systemManageService.refreshSuperAuthor();
		
		return ret;						
	}
	
	@ApiDesc("修改个人信息")
	@RequestMapping(value="/updatepersoninfo")
	public Object updatePersonInfo(HttpServletRequest request,@RequestBody LoginEnity loginEnity) {
		
		String token = TokenUtil.getTokenFromRequest(request);
		
		ResponseEntity<String> ret = systemManageService.updatePersonInfo(token,loginEnity);
		
		return ret;						
	}
	
	@ApiDesc("删除菜单")
	@RequestMapping(value="/deletemenu")
	public Object deleteMenu(HttpServletRequest request,String menu_id) {
		
		ResponseEntity<String> ret = systemManageService.deleteMenu(menu_id);
		
		return ret;						
	}
	
	@ApiDesc("上传文件")
	@RequestMapping(value="/uploadfile")
	public Object uploadFile(HttpServletRequest request,MultipartFile file,String relation_id,String file_type
							,@RequestParam(required = false,defaultValue = "1") Boolean isRecord) {
		
		String token = TokenUtil.getTokenFromRequest(request);
		
		ResponseEntity<FileEntity> ret = systemManageService.uploadFile(file,relation_id,file_type,token,isRecord);
		
		return ret;				
	}
	
	@ApiDesc("重置用户密码")
	@RequestMapping(value="/resetpassword")
	public Object resetPassword(HttpServletRequest request,String login_id) {
		
		ResponseEntity<String> ret = systemManageService.resetPassword(login_id);
		
		return ret;			
	}
	
	@ApiDesc("获取角色关联菜单")
	@RequestMapping(value="/getrolemenurelation")
	public Object getRoleMenuRelation(HttpServletRequest request,String role_id) {
		
		ResponseEntity<String> ret = systemManageService.getRoleMenuRelation(role_id);
		
		return ret;				
	}
	
	@ApiDesc("修改角色")
	@RequestMapping(value="/updaterole")
	public Object updateRole(HttpServletRequest request,@RequestBody LoginRole loginRole) {
		
		ResponseEntity<String> ret = systemManageService.updateRole(loginRole);
		
		return ret;			
	}
	
	@ApiDesc("删除角色")
	@RequestMapping(value="/deleterole")
	public Object deleteRole(HttpServletRequest request,String role_id) {
		
		ResponseEntity<String> ret = systemManageService.deleteRole(role_id);
		
		return ret;				
	}
	
	@ApiDesc("添加角色")
	@RequestMapping(value="/addrole")
	public Object addRole(HttpServletRequest request,@RequestBody LoginRole loginRole) {
		
		ResponseEntity<String> ret = systemManageService.addRole(loginRole);
		
		return ret;		
	}
	
	@ApiDesc("获取用菜单树")
	@RequestMapping(value="/getmenutree")
	public Object getMenuTree(HttpServletRequest request) {
		
		ResponseEntity<TreeEntity> ret = systemManageService.getMenuTree();
		
		return ret;					
	}
	
	@ApiDesc("更改用户信息")
	@RequestMapping(value="/updateuser")
	public Object updateUser(HttpServletRequest request,@RequestBody LoginEnity loginEntity) {
		
		ResponseEntity<String> ret = systemManageService.updateUser(loginEntity);
		
		return ret;				
	}
	
	@ApiDesc("删除用户")
	@RequestMapping(value="/deleteuser")
	public Object deleteUser(HttpServletRequest request,String login_id) {
		
		String token = TokenUtil.getTokenFromRequest(request);
		
		ResponseEntity<String> ret = systemManageService.deleteUser(login_id,token);
		
		return ret;				
	}
	
	@ApiDesc("添加用户")
	@RequestMapping(value="/adduser")
	public Object addUser(HttpServletRequest request,@RequestBody LoginEnity loginEntity) {
		
		ResponseEntity<String> ret = systemManageService.addUser(loginEntity);
		
		return ret;				
	}
	
	@ApiDesc("获取用户角色")
	@RequestMapping(value="/getallroles")
	public Object getAllRoles(HttpServletRequest request,LoginRole loginRole) {
		
		ResponseEntity<LoginRole> ret = systemManageService.getAllRoles(loginRole);
		
		return ret;			
	}
	
	@ApiDesc("查询角色列表")
	@RequestMapping(value="/queryrolesforpage")
	public Object queryRolesForPage(HttpServletRequest request,@RequestBody PageRequestBean<LoginRole> pagerequest) {
		
		ResponseEntity<PageResponseBean<LoginRole>> ret = systemManageService.queryRolesForPage(pagerequest);
		
		return ret;	
	}
	
	@ApiDesc("查询用户列表")
	@RequestMapping(value="/queryloginlist")
	public Object queryLoginList(HttpServletRequest request,@RequestBody PageRequestBean<LoginEnity> pagerequest) {
		
		ResponseEntity<PageResponseBean<LoginEnity>> ret = systemManageService.queryLoginList(pagerequest);
		
		return ret;				
	}
	
	@ApiDesc("添加菜单")
	@RequestMapping(value="/addmenu")
	public Object addMenu(HttpServletRequest request,MenuEntity menuEntity) {
		
		ResponseEntity<String> ret = systemManageService.addMenu(menuEntity);
		
		return ret;		
	}
	
	@ApiDesc("查询菜单列表")
	@RequestMapping(value="/querymenulist")
	public Object queryMenuList(HttpServletRequest request,MenuEntity menuEntity) {
		
		ResponseEntity<MenuEntity> ret = systemManageService.queryMenuList(menuEntity);
		
		return ret.getRetlist();			
	}
	
	@ApiDesc("查询组织机构列表")
	@RequestMapping(value="/queryorglist")
	public Object queryOrgList(HttpServletRequest request,Organization organization) {
		
		ResponseEntity<Organization> ret = systemManageService.queryOrgList(organization);
		
		return ret.getRetlist();			
	}
	
	@ApiDesc("修改菜单信息")
	@RequestMapping(value="/updatemenu")
	public Object updateMenu(HttpServletRequest request,MenuEntity menuEntity) {
		
		ResponseEntity<String> ret = systemManageService.updateMenu(menuEntity);
		
		return ret;	
	}
	
	@ApiDesc("删除组织机构及其子机构")
	@RequestMapping(value="/deleteorg")
	public Object deleteOrg(HttpServletRequest request,Organization organization) {
		
		ResponseEntity<String> ret = systemManageService.deleteOrg(organization);
		
		return ret;			
	}
	
	@ApiDesc("添加组织机构")
	@RequestMapping(value="/addorg")
	public Object addOrg(HttpServletRequest request,@RequestBody Organization organization) {
		
		ResponseEntity<String> ret = systemManageService.addOrg(organization);
		
		return ret;			
	}
	
	@ApiDesc("修改组织机构")
	@RequestMapping(value="/updateorg")
	public Object updateOrg(HttpServletRequest request,@RequestBody Organization organization) {
		
		ResponseEntity<String> ret = systemManageService.updateOrg(organization);
		
		return ret;				
	}
	
	@ApiDesc("验证编码唯一性")
	@RequestMapping(value="/validdictcode")
	public Object validDictCode(HttpServletRequest request,@RequestParam Integer word_code) {
		
		ResponseEntity<String> ret = systemManageService.validDictCode(word_code);
		
		return ret;			
	}
	
	@ApiDesc("查询词典数据")
	@RequestMapping(value="/querydictlist")
	public Object queryDictList(HttpServletRequest request,DictEntity dictEntity) {
		
		ResponseEntity<DictEntity> ret = systemManageService.queryDictList(dictEntity);
		
		return ret;			
	}
	
	@ApiDesc("分页查询数据词典")
	@RequestMapping(value="/querydictforpage")
	public Object queryDictForPage(HttpServletRequest request,@RequestBody PageRequestBean<DictEntity> pagerequest) {
		
		ResponseEntity<PageResponseBean<DictEntity>> ret = systemManageService.queryDictForPage(pagerequest);
		
		return ret;			
	}
	
	@ApiDesc("添加数据词典")
	@RequestMapping(value="/adddict")
	public Object addDict(HttpServletRequest request,@RequestBody DictEntity dictEntity) {
		
		ResponseEntity<String> ret = systemManageService.addDict(dictEntity);
		
		return ret;			
	}
	
	@ApiDesc("删除词典数据")
	@RequestMapping(value="/deletedict")
	public Object deleteDict(HttpServletRequest request,Integer word_code) {
		
		ResponseEntity<String> ret = systemManageService.deleteDict(word_code);
		
		return ret;			
	}
	
	@ApiDesc("修改词典数据")
	@RequestMapping(value="/updatedict")
	public Object updateDict(HttpServletRequest request,@RequestBody DictEntity dictEntity) {
		
		ResponseEntity<String> ret = systemManageService.updateDict(dictEntity);
		
		return ret;			
	}
}
